﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class MenuItem : MonoBehaviour
{
    public Toggle SelfToggle;
    public Transform ContentTrans;
    public Text NameText;
    public string FirstLevName;
    public Transform FatherItem;
    public List<Transform> ChildItemTrans = new List<Transform>();

	// Use this for initialization
	void Start ()
	{
	    this.SelfToggle.onValueChanged.AddListener((toggleIsTrue) =>
	    {
	        if (toggleIsTrue)
	        {
	            this.SelfToggle.transform.localEulerAngles = new Vector3(0, 0, 0);
                foreach (var childTrans in this.ChildItemTrans)
	            {
	                childTrans.gameObject.SetActive(true);
	            }
	        }
	        else
	        {
	            this.HideAllChild(this.transform);
	        }
	    });

	}

    private void HideAllChild(Transform item)
    {
        if (item.GetComponent<MenuItem>().ChildItemTrans.Count != 0)
        {
            item.GetComponent<MenuItem>().SelfToggle.transform.localEulerAngles = new Vector3(0, 0, 90);
            for (int i = 0; i < item.GetComponent<MenuItem>().ChildItemTrans.Count; i++) 
            {
                item.GetComponent<MenuItem>().HideAllChild(item.GetComponent<MenuItem>().ChildItemTrans[i]);
                item.GetComponent<MenuItem>().ChildItemTrans[i].gameObject.SetActive(false);
            }
        }
    }

}
